const express = require("express")
const cors = require('cors')
const { compose } = require("@reduxjs/toolkit")
const app = express()

app.use(cors())
app.use(express.json())


app.post("/login",(req,res)=>{
    let account = req.body.account
    let password = req.body.password
    let obj = {
        msg:"登录成功"
    }

    if(account == "admin" && password == "1"){
        obj.id = "1"
        res.json(obj)
    }else if(account == "admin" && password == "2"){
        obj.id = "2"
        res.json(obj)
    }else if(account == "admin" && password == "3"){
        obj.id = "3"
        res.json(obj)
    }else{
        obj.msg = "登录失败"
        res.json(obj)
    }
})

let routeRight = [
    {
        path:"/page1",
        component:"Page1"
    },
    {
        path:"/page2",
        component:"Page2"
    },
    {
        path:"/page3",
        component:"Page3",
        children:[
            {
                path:"son1",
                component:"Page3Son1",
            },
            {
                path:"son2",
                component:"Page3Son2",
            }
        ]
    }
]

app.get("/getroute",(req,res)=>{
   
    let id = req.query.id
    console.log(req.query,id == "1")
    if(id == "1"){
        res.json({
            data:routeRight
        })
    }else if(id == "2"){
        let arr = JSON.parse(JSON.stringify(routeRight))
        arr.splice(1,1)
        res.json({
            data:arr
        })
    }else if(id == "3"){
        let arr = JSON.parse(JSON.stringify(routeRight))
        arr.splice(2,1)
        res.json({
            data:arr
        })
    }else{
        res.json({
            data:[]
        })
    }
})





app.listen(8001,()=>{
    console.log("80001监听成")
})